<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>${subject.name}</title>
<link href="${pageContext.request.contextPath}/assets/css/amazeui.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath}/assets/css/admin.css" rel="stylesheet" type="text/css" />
 
</head>
<body>
<form class="am-form">
  <fieldset>
 	 <legend>${subject.name}</legend>
	<c:forEach items="${tests}" var="test" varStatus="status">
		<div class="timu" timuid="${test.id}" grade="${test.grade}">
			<div class="title"><span><c:out value="${status.index+1}"/>.</span>  
			${test.content}</div>
			<div class="content">
				<c:forEach items="${test.answers}" var="answer">
					<div class="am-radio">
     				 	<label>
							<input type="radio" class="answer" name="doc-radio-1" value="${answer.id}" >
							${answer.content}
						</label>
					</div>
				</c:forEach>
			</div>
		</div>
		</li>
	</c:forEach>
	<button id="finishtest" class="am-btn am-btn-default" >提交试卷</button>
	<button id="testone" class="am-btn am-btn-default" type="button">测试</button>
	</fieldset>
</form>	
	<script  src="${pageContext.request.contextPath}/assets/js/jquery.min.js"></script>
	<script  src="${pageContext.request.contextPath}/assets/js/layer.js"></script>
	<script  src="${pageContext.request.contextPath}/assets/js/amazeui.min.js"></script>
	<script  src="${pageContext.request.contextPath}/assets/js/app.js"></script>
	<script>
  $(document).ready(function () {
	  $("#testone").click(function(){
		 // alert($("input[type='radio']:checked").val());
		 var tests=new Array();
		 $(".timu").each(function(index){
			 var test=new Object();
			 //SubjectId,StudentId,Score,time
			  var tid=$(this).attr("timuid");
			 var answer=$(this).find("input[name='doc-radio-1']:checked").val();
			  if(answer==null){
				  alert("你什么都没选择,请选择后继续");
				  return false;
			  }
			  test.tid=tid;
			  test.answer=answer;
			  test.grade=$(this).attr("grade");
			  tests.push(test);
		  });
		 if(tests!=null){
			 var testsjson=JSON.stringify(tests);
			// alert(testsjson);
			 $.ajax({
					url:'${pageContext.request.contextPath}/test/finishtest',	
					type:'POST',
					async:false,
					data:{tests:testsjson,time:"3600",subjectid:"${subject.id}"},
					error:function(jqXHR,textStatus,errorThrown){
						if(textStatus=="error"){
							layer.msg('内部服务错误！请联系网站管理员');
						}
					},
					success:function(data,status){
						if(data!="false"){
							layer.msg("回复成功")
							location.reload();
						}
						else{
							layer.msg('回复失败');
						}
					}
				});
		 }
	  });
		//alert("开始");
		$("#finishtest").click(function(){
			$.ajax({
				url:'${pageContext.request.contextPath}/test/finishtest',	
				type:'POST',
				async:false,
				data:{editorValue:$("#ueditor_textarea_editorValue").val(),tid:$("#taskid").val()},
				error:function(jqXHR,textStatus,errorThrown){
					if(textStatus=="error"){
						layer.msg('内部服务错误！请联系网站管理员');
					}
				},
				success:function(data,status){
					if(data!="false"){
						layer.msg("回复成功")
						location.reload();
					}
					else{
						layer.msg('回复失败');
					}
				}
			});
		});
	 });
  </script>
</body>
</html>